home *** CD-ROM | disk | FTP | other *** search
/ PC Open 107 / PC Open 107 CD 1.bin / CD1 / INTERNET / COPIA SITI / Getleft / getleft-setup-notcl.exe / {app} / scripts / EnterUrl.tcl < prev    next >
Encoding:
Text File  |  2004-05-25  |  9.8 KB  |  266 lines

  1. ###############################################################################
  2. ###############################################################################
  3. ##                          EnterUrl
  4. ###############################################################################
  5. ###############################################################################
  6. ## Takes care of the dialog that prompts the user for an Url to download.
  7. ###############################################################################
  8. ###############################################################################
  9. ## (c) 2002-2004 AndrΘs Garcφa Garcφa. fandom@retemail.es
  10. ## You may distribute the contents of this file under the terms of the GPL v2
  11. ###############################################################################
  12. ###############################################################################
  13.  
  14. namespace eval EnterUrl {
  15.  
  16. ###############################################################################
  17. # EnterUrlChangeDir {currentDir}
  18. #    Invoked when the user want to change the directory in which the site
  19. #    will be saved.
  20. #
  21. # Side effect:
  22. #    If the user actually changes the directory, the new one will be shown
  23. #    in the 'Enter Url' dialog
  24. ###############################################################################
  25. proc EnterUrlChangeDir {} {
  26.     global   env
  27.     variable window
  28.  
  29.     if {$window(dir)!=$env(HOME)} {
  30.         set currentDir [file dirname $window(dir)]
  31.     } else {
  32.         set currentDir $env(HOME)
  33.     }
  34.  
  35.     set window(baseDir) [Dialogos::SelectDirectory $currentDir .enterUrlWindow]
  36.  
  37.     if {$window(baseDir)!=""} {
  38.         set window(dir)   [file nativename $window(baseDir)]
  39.     }
  40.  
  41.     return
  42. }
  43.  
  44. ###############################################################################
  45. # EnterUrlWindow
  46. #    Creates a dialog box where you can write or paste the desired url.
  47. #
  48. # Parameter:
  49. #    parent: The path of the toplevel window over which it will appear.
  50. #    url:    The url that will appear in the dialog, if none is given it will
  51. #            look in the selection.
  52. #
  53. # Returns:
  54. #    The path of the entry in the combobox.
  55. ################################################################################
  56. proc EnterUrlWindow {parent url} {
  57.     global labelButtons labelTitles labelFrames labelDialogs labelMenus
  58.     global urlHistory getleftState getleftOptions dirGetleft
  59.     global indexButtons indexDialogs
  60.     variable window
  61.  
  62.     set coord(x) [winfo rootx $parent]
  63.     set coord(y) [winfo rooty $parent]
  64.  
  65.     set win [toplevel .enterUrlWindow]
  66.     wm title $win $labelTitles(enterUrl)
  67.     wm resizable $win 0 0
  68.     wm geometry  $win +[expr {$coord(x)+100}]+[expr {$coord(y)+15}]
  69.  
  70.     set marcoEx [frame $win.marcoEx]
  71.     set marcoUrl [fl::FrameLabel $marcoEx.marco -bd 2 -relief groove                      \
  72.             -textvariable labelFrames(webPage)]
  73.     set marcoUrlIn [frame $marcoUrl.marcoIn]
  74.  
  75.     set urlCombo [Ccombinado::ComboBox $marcoUrlIn.url $urlHistory                        \
  76.             -erasable 1  -default $url -fg $getleftOptions(fg)                            \
  77.             -bg $getleftOptions(bg) -textvariable EnterUrl::window(url)]
  78.     set startCheck [underButton::UnderButton $marcoUrlIn.start -buttontype checkbutton    \
  79.             -variable getleftState(startNow)                                              \
  80.             -textvariable labelDialogs(startNow) -under $indexDialogs(startNow)]
  81.  
  82.     set dirFrame    [fl::FrameLabel $marcoEx.dirFrame -bd 2 -relief groove                \
  83.             -textvariable labelFrames(dir)]
  84.     set dirIntFrame [frame $dirFrame.intFrame]
  85.     set dirEntry [menuEntry::menuEntry $dirIntFrame.entry -width 40                       \
  86.             -bg $getleftOptions(bg) -fg $getleftOptions(fg)                               \
  87.             -textvariable EnterUrl::window(dir)]
  88.  
  89.     set dirButton [underButton::UnderButton $dirIntFrame.button -buttontype button        \
  90.             -width 10 -command "EnterUrl::EnterUrlChangeDir"                              \
  91.             -textvariable labelButtons(select) -under $indexButtons(select)               \
  92.             ]
  93.     set window(dir)   [file nativename $dirGetleft(lastDir)]
  94.  
  95.     $dirEntry xview moveto 1.0
  96.  
  97.     set buttons [frame $win.buttons]
  98.     set start   [underButton::UnderButton $buttons.start   -textvariable labelButtons(start)  \
  99.             -width 8 -command "EnterUrl::EnterUrlControl 1" -under $indexButtons(start)       \
  100.             -buttontype button ]
  101.     set cancel  [underButton::UnderButton $buttons.cancel  -textvariable labelButtons(cancel) \
  102.             -width 8 -command "EnterUrl::EnterUrlControl 0" -under $indexButtons(cancel)      \
  103.             -buttontype button ]
  104.     set options [underButton::UnderButton $buttons.options -textvariable labelButtons(options)\
  105.             -width 8 -command "Opciones::ChooseOptions ::downOptionsTemp $win"                \
  106.             -buttontype button  -under $indexButtons(options)]
  107.  
  108.  
  109.     set window(win)        $win
  110.     set window(combo)      $urlCombo
  111.     set window(dirEntry)   $dirEntry
  112.     set window(startCheck) $startCheck
  113.  
  114.     bind $urlCombo.entry <Return>   "focus $dirEntry"
  115.     bind $urlCombo.entry <KP_Enter> "focus $dirEntry"
  116.  
  117.     bind $dirEntry       <Return>   "focus $start"
  118.     bind $dirEntry       <KP_Enter> "focus $start"
  119.  
  120.     bind $win            <Escape>   "$cancel invoke"
  121.  
  122.     pack $marcoEx     -padx 10
  123.  
  124.     pack $marcoUrl    -ipady 10 -pady 10 -fill x
  125.     pack $marcoUrlIn  -side bottom -padx 20
  126.     pack $urlCombo   
  127.     pack $startCheck  -pady 5 -side left
  128.  
  129.     pack $dirFrame    -ipady 10    -fill both
  130.     pack $dirIntFrame -side left   -fill x    -padx 20
  131.     pack $dirEntry    -side left   -pady 5
  132.     pack $dirButton   -side left   -padx 5 
  133.  
  134.     pack $buttons     -side bottom -padx 7 -fill x
  135.     pack $cancel $start $options -side right -padx 3 -pady 5
  136.  
  137.     focus $urlCombo.entry
  138.  
  139.     return $urlCombo.entry
  140. }
  141.  
  142. ###############################################################################
  143. # EnterUrlControl
  144. #    Checks the url entered and complains if it is not valid.
  145. #    In practice, in considers just about anything to be valid.
  146. #
  147. # Parameter
  148. #    done: '1' if the user clicked on start, '0' if he cancelled.
  149. ################################################################################
  150. proc EnterUrlControl {done} {
  151.     global labelTitles labelMessages
  152.     global dirGetleft  directories getleftState
  153.     variable window
  154.  
  155.     if {($done==0)||($window(url)=="")} {
  156.         $window(combo).entry selection clear
  157.         $window(dirEntry)    selection clear
  158.         wm withdraw $window(win)
  159.         return
  160.     }
  161.  
  162.     set requestedUrl [string trim $window(url)]
  163.     set parsedUrl    [HtmlParser::ParseUrl $requestedUrl]
  164.  
  165.     if {$parsedUrl==1} {
  166.         tk_messageBox -title $labelTitles(error) -icon error -type ok         \
  167.                 -message "$labelMessages(noWWW)\n$requestedUrl"               \
  168.                 -parent $window(win)
  169.         return
  170.     }
  171.  
  172.     set dir $window(dir)
  173.     if {$dir==""} {
  174.         tk_messageBox -type ok -icon error -title $labelTitles(error)         \
  175.                 -message "Please, enter a directory" -parent $window(win)
  176.         return
  177.     }
  178.     regsub -all {\\} $dir             {/} window(baseDir)
  179.     regsub      {/$} $window(baseDir) {}  window(baseDir)
  180.     if {![file exists $window(baseDir)]} {
  181.        set what [tk_messageBox -icon question                                 \
  182.             -message $labelMessages(unknown) -title $labelTitles(unknown)     \
  183.             -parent $window(win) -type yesno]
  184.        switch $what {
  185.             yes {
  186.                 file mkdir $window(baseDir)
  187.             }
  188.             no return
  189.       }
  190.     } else {
  191.        if {![file isdirectory $window(baseDir)]} {
  192.            tk_messageBox -type ok -icon error -title $labelTitles(error)     \
  193.                     -message "Please, enter a directory" -parent $window(win)
  194.            return
  195.        }
  196.     }
  197.     wm withdraw $window(win)
  198.  
  199.     regsub -all {\n}   $requestedUrl {}  requestedUrl
  200.     regsub -all {\\}   $requestedUrl {/} requestedUrl
  201.     regsub -all {\x00} $requestedUrl {}  requestedUrl
  202.  
  203.     set domain [string tolower [lindex [HtmlParser::ParseUrl $requestedUrl] 1]]
  204.  
  205.     PutUrlInHistory $requestedUrl
  206.  
  207.     PutUrlInQueue $requestedUrl $window(baseDir) [array get ::downOptionsTemp]
  208.  
  209.     set dirGetleft(lastDir) $window(baseDir)
  210.  
  211.     if {($getleftState(downloading)==0)&&($getleftState(startNow)==1)} {
  212.         StartDownload $requestedUrl
  213.     }
  214.  
  215.     return
  216. }
  217.  
  218. ###############################################################################
  219. # EnterUrl
  220. #    Creates a dialog box where you can write or paste the desired url.
  221. #
  222. # Parameters
  223. #    map: '1' if the user wants a map of the site.
  224. #    parent: The window over which the dialog should appear.
  225. #    url: The url to download if available.
  226. #    label: The tag of the url in the 'Choose Files' dialog.
  227. #
  228. # Returns:
  229. #    The url entered by the user.
  230. ###############################################################################
  231. proc EnterUrl {{map 0} {parent .} {url ""} {label ""}} {
  232.     global getleftOptions downOptions downOptionsTemp getleftState
  233.     variable window
  234.  
  235.     if {[winfo exists .enterUrlWindow]} {
  236.         raise $window(win) .
  237.         if {[wm state $window(win)]!="withdrawn"} {
  238.             return
  239.         }
  240.         if {$getleftState(downloading)==1} {
  241.             $window(startCheck) configure -state disabled
  242.         } else {
  243.             $window(startCheck) configure -state normal
  244.         }
  245.     }
  246.  
  247.     catch "unset ::downOptionsTemp"
  248.     array set downOptionsTemp [array get downOptions]
  249.     set downOptionsTemp(map) $map
  250.  
  251.     if {![winfo exists .enterUrlWindow]} {
  252.         EnterUrlWindow $parent $url
  253.     }
  254.     if {$url!=""} {
  255.         set window(url) $url
  256.     } else {
  257.         set window(url) [menuEntry::ReadSel]
  258.     }
  259.  
  260.     set Ccombinado::cbArgs(items) $::urlHistory
  261.     wm deiconify $window(win)
  262.     
  263.     return
  264. }
  265. }
  266.